<template>
  <div class="login">
    <div class="login_all">
      <div class="login_top">
        <div class="login_back" @click="back"></div>
        <router-link to="reg"><div class="reg_name">注册</div></router-link>
      </div>
      <div class="welcome">
        你好<br />
        欢迎来到寻匠之美
      </div>
      <div class="phone">
        <input
          type="text"
          v-model.trim="phone"
          oninput="value=value.replace(/[^\d]/g,'')"
          v-on:input="canon"
          class="login_inp"
          maxlength="11"
          placeholder="请输入手机号"
        />
      </div>
      <div class="password">
        <input
          :type="inputType"
          v-model.trim="password"
          class="login_inp"
          v-on:input="canon"
          placeholder="请输入密码"
          maxlength="12"
        />
        <div :class="eye ? 'see' : 'eye'" @click="showPass"></div>
      </div>
      <div class="login_div">
        <input
          type="button"
          :class="rule ? 'login_true' : 'login_btn'"
          @click="login"
          :disabled="!rule"
          value="登录"
        />
      </div>
      <div class="login_other">
        <router-link to="note"
          ><div class="login_note">短信登录</div></router-link
        >
        <router-link to="forget"
          ><div class="login_forget">忘记密码？</div></router-link
        >
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "Login",
  data() {
    return {
      eye: true,
      inputType: "password",
      phone: "",
      rule: false,
      password: "",
    };
  },
  created() {
    document.title = "登录";
  },
  methods: {
    back() {
      this.$router.go(-2);
    },
    showPass() {
      this.eye = !this.eye;
      if (this.eye) {
        this.inputType = "password";
      } else {
        this.inputType = "text";
      }
    },
    canon() {
      if (this.phone.length == 11 && this.password.length >= 6) {
        this.rule = true;
      } else {
        this.rule = false;
      }
    },
    login() {
      var that = this;
      that.$axios
        .post("/v1/common/login", {
          mobile: that.phone,
          login_type: "1",
          password: that.password,
        })
        .then(
          (res) => {
            var result = res.data;
            if (result.code == 200) {
              var token = result.data.token;
              localStorage.setItem("token", token);
              //    this.$router.push({path:'/center'});
              setTimeout(function () {
                that.$router.go(-1);
              }, 500);
            } else {
              Toast(result.msg);
            }
          },
          (res) => {
            console.log("error");
          }
        );
    },
  },
};
</script>
<style scoped>
.login {
  width: 100%;
  position: fixed;
  height: 100%;
}
.login_all {
  width: 698px;
  margin: 0 auto;
}
.login_top {
  display: flex;
  justify-content: space-between;
  margin-top: 30px;
}
.login_top a {
  text-decoration: none;
}
.login_back {
  width: 48px;
  height: 48px;
  background: url("/static/images/team_go_back.png") no-repeat center center;
  background-size: 100% 100%;
}
.reg_name {
  color: #000;
  font-size: 32px;
}
.password {
  position: relative;
}
.see {
  width: 48px;
  height: 48px;
  background: url("/static/images/see.png") no-repeat center center;
  background-size: 100% 100%;
  position: absolute;
  right: 0;
  top: 34px;
}
.eye {
  width: 48px;
  height: 48px;
  background: url("/static/images/eye.png") no-repeat center center;
  background-size: 100% 100%;
  position: absolute;
  right: 0;
  top: 34px;
}
.welcome {
  font-size: 52px;
  color: #333333;
  font-weight: bold;
  margin-top: 56px;
  margin-bottom: 60px;
}
.login_inp {
  border: none;
  width: 100%;
  height: 104px;
  border-bottom: 2px solid #ececec;
  font-size: 32px;
}
.login_btn {
  width: 100%;
  height: 98px;
  line-height: 100px;
  border-radius: 50px;
  text-align: center;
  font-size: 32px;
  color: #4a4a4a;
  background: #ececec;
  margin-top: 70px;
  cursor: pointer;
  outline: 0px;
  -webkit-appearance: none;
  border: none;
}
.login_true {
  width: 100%;
  height: 98px;
  line-height: 100px;
  border-radius: 50px;
  text-align: center;
  font-size: 32px;
  color: #333334;
  background: #ffe514;
  margin-top: 70px;
  cursor: pointer;
  outline: 0px;
  -webkit-appearance: none;
  border: none;
}
.login_other {
  display: flex;
  justify-content: space-between;
  margin-top: 50px;
  font-size: 28px;
  color: #9b9b9b;
}
.login_other a {
  text-decoration: none;
}
.login_note {
  color: #9b9b9b;
}
.login_forget {
  color: #9b9b9b;
}
</style>